package com.hksj.Intelligentmanagement.controller;

import com.hksj.Intelligentmanagement.common.Result;
import com.hksj.Intelligentmanagement.dto.MqttAuthDTO;
import com.hksj.Intelligentmanagement.service.MqttAuthService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;


/**
 * @ClassName EmqAuthController
 * @Description TODO
 * @Author @陈章 @zengke
 * @Date 2023/3/8 14:17
 * @Version 1.0
 */
@Api(tags = "mqtt连接参数管理")
@RestController
@RequestMapping("/mqtt")
public class MqttAuthController {


    @Autowired
    private MqttAuthService mqttAuthService;

    @ApiOperation("新增mqtt认证参数")
    @PostMapping("/createMqttAuth")
    public Result createMqttAuth(@RequestBody MqttAuthDTO mqttAuthDTO){
        return mqttAuthService.createMqttAuth(mqttAuthDTO);
    }

    @ApiOperation("删除mqtt认证参数")
    @DeleteMapping("/deleteMqttAuth/{id}")
    public Result deleteMqttAuth(@PathVariable("id") String id){
        return mqttAuthService.deleteMqttAuth(id);
    }

    @ApiOperation("修改mqtt参数")
    @PutMapping("/updateMqttAuth")
    public Result updateMqttAuth(@RequestBody MqttAuthDTO mqttAuthDTO){
        return mqttAuthService.updateMqttAuth(mqttAuthDTO);
    }

    @ApiOperation("动态分页查询mqtt参数列表")
    @PostMapping("/queryMqttAuthListByPage")
    public Result queryMqttAuthListByPage(@RequestBody MqttAuthDTO mqttAuthDTO){
        return Result.ok(mqttAuthService.queryMqttAuthListByPage(mqttAuthDTO));
    }

    @ApiOperation(value = "mqttAuth认证")
    @PostMapping("/auth")
    public ResponseEntity<Object> auth(@RequestParam("clientid") String clientid,
        @RequestParam("username") String username, @RequestParam("password") String password) {
            return mqttAuthService.auth(clientid, username, password);
    }

    //超级用户判断
    @ApiOperation(value = "判断客户端是否是超级用户")
    @PostMapping("/superuser")
    public ResponseEntity<Object> superuser(@RequestParam("clientid") String clientid, @RequestParam("username") String username){
        return mqttAuthService.superuser(clientid,username);
    }

    //acl授权请求
    @ApiOperation(value = "acl授权请求")
    @PostMapping("/acl")
    public ResponseEntity<Object> acl(@RequestParam("access") int access, @RequestParam("username")String username,
                              @RequestParam("clientid")String clientid,@RequestParam("ipaddr")String ipaddr,
                              @RequestParam("topic")String topic,@RequestParam("mountpoint")String mountpoint){

       return mqttAuthService.acl(access, username, clientid, ipaddr, topic, mountpoint);
    }
}
